-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Observability AI Assistant] migrate to inference client #197630 #199286
[Observability AI Assistant] migrate to inference client #197630 #199286
Conversation
Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant) |
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
60177d0
to
a3b2644
Compare
throw createInternalServerError( | ||
`${executeResult?.message} - ${executeResult?.serviceMessage}` | ||
); | ||
): Observable<ChatCompletionEvent> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we encapsulate the event type from the inference client here, and convert it into ChatCompletionChunkEvent
. We should eventually completely drop ChatCompletionChunkEvent
in favor of the inference plugin's types, but that means that we need to make changes in many places, and there's some stuff that isn't supported yet by the Inference plugin's types. Until that happens, I think we should limit the blast radius and stick to our own types where we can - which should be everywhere except for the implementation of this function, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, I will use ChatEvent to maintain compatibility with existing types (ChatCompletionChunkEvent
, and TokenCountEvent
) and adding InferenceChatCompletionChunkEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, what I mean is that we only have ChatCompletionChunkEvent
(which is exclusive to the Obs AI Assistant). Any event from the Inference client is ideally not exposed via the chat
method. So the signature of the chat
method should stay the same, and existing types as well. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense. I’ll keep the ChatCompletionChunkEvent
as the main event type for the ObservabilityAIAssistantClient.chat
method to ensure we don’t expose any inference-client-specific types directly. I’ll handle the conversion internally within the implementation, encapsulating the inference client events as needed without altering the existing method signature or exposing the InferenceChatCompletionChunkEvent
.
- Solution:
Within the pipe, we’ll add a mapping step to convert any incomingInferenceChatCompletionChunkEvent
to aChatCompletionChunkEvent
type. should I do it for all the event emitted frominferenceClient.complete
method?
for these 3 inference client events:
export type ChatCompletionEvent<TToolOptions extends ToolOptions = ToolOptions> =
| ChatCompletionChunkEvent
| ChatCompletionTokenCountEvent
| ChatCompletionMessageEvent<TToolOptions>;
c59ff8b
to
df2a179
Compare
tools, | ||
}) | ||
).pipe( | ||
convertInferenceEventsToStreamingEvents(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgieselaar
convertInferenceEventsToStreamingEvents converts any InferenceChatCompletionEvent types to their corresponding StreamingChatResponseEvent types, such as ChatCompletionChunkEvent, TokenCountEvent, ensuring we maintain compatibility with existing event types. This keeps the ObservabilityAIAssistantClient.chat method’s signature intact and avoids exposing inference-client-specific types directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++, this looks good!
df2a179
to
200217b
Compare
x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/index.ts
Show resolved
Hide resolved
x-pack/test/observability_ai_assistant_api_integration/common/create_openai_chunk.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana.jsonc
LGTM
ef466d1
to
578d51e
Compare
} | ||
|
||
await simulator.tokenCount({ completion: 20, prompt: 33, total: 53 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you manually calculate these? If the input chunks are changed, will the token counts go out of sync without us noticing? Theres nothing that actually counts the tokens and require the token count to match?
…I Assistant client
…ion calls in AI Assistant tests
…create_openai_chunk.ts Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…nt/server/service/client/operators/convert_inference_events_to_streaming_events.ts Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…nt/server/service/client/operators/convert_inference_events_to_streaming_events.ts Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
…vents and simplify token count extraction
1040c29
to
2355ca4
Compare
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Page load bundle
History
|
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12234966215 |
… (elastic#199286) ## Summary Closes elastic#183245 Closes elastic#197630 [Observability AI Assistant] Partially migrate to inference client replacing `inferenceClient.chatComplete` to `observabilityAIAssistantClient.chat` - `observabilityAIAssistantClient.complete` does a bunch of stuff on top of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper for now because it also adds instrumentation and logging. (cherry picked from commit df0dfa5)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
#199286) (#203399) # Backport This will backport the following commits from `main` to `8.x`: - [[Observability AI Assistant] migrate to inference client #197630 (#199286)](#199286) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Arturo Lidueña","email":"arturo.liduena@elastic.co"},"sourceCommit":{"committedDate":"2024-12-09T11:46:31Z","message":"[Observability AI Assistant] migrate to inference client #197630 (#199286)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630 \r\n[Observability AI Assistant] Partially migrate to inference client \r\n\r\nreplacing `inferenceClient.chatComplete` to\r\n`observabilityAIAssistantClient.chat` -\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper\r\nfor now because it also adds instrumentation and logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Obs AI Assistant","ci:project-deploy-observability","backport:version","v8.18.0"],"title":"[Observability AI Assistant] migrate to inference client #197630","number":199286,"url":"https://github.com/elastic/kibana/pull/199286","mergeCommit":{"message":"[Observability AI Assistant] migrate to inference client #197630 (#199286)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630 \r\n[Observability AI Assistant] Partially migrate to inference client \r\n\r\nreplacing `inferenceClient.chatComplete` to\r\n`observabilityAIAssistantClient.chat` -\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper\r\nfor now because it also adds instrumentation and logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199286","number":199286,"mergeCommit":{"message":"[Observability AI Assistant] migrate to inference client #197630 (#199286)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/183245\r\n\r\nCloses #197630 \r\n[Observability AI Assistant] Partially migrate to inference client \r\n\r\nreplacing `inferenceClient.chatComplete` to\r\n`observabilityAIAssistantClient.chat` -\r\n`observabilityAIAssistantClient.complete` does a bunch of stuff on top\r\nof `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper\r\nfor now because it also adds instrumentation and logging.","sha":"df0dfa5216c1d1d3b72a30b3b1d903781db90615"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Arturo Lidueña <arturo.liduena@elastic.co>
… (elastic#199286) ## Summary Closes elastic#183245 Closes elastic#197630 [Observability AI Assistant] Partially migrate to inference client replacing `inferenceClient.chatComplete` to `observabilityAIAssistantClient.chat` - `observabilityAIAssistantClient.complete` does a bunch of stuff on top of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper for now because it also adds instrumentation and logging.
… (elastic#199286) ## Summary Closes elastic#183245 Closes elastic#197630 [Observability AI Assistant] Partially migrate to inference client replacing `inferenceClient.chatComplete` to `observabilityAIAssistantClient.chat` - `observabilityAIAssistantClient.complete` does a bunch of stuff on top of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper for now because it also adds instrumentation and logging.
… (elastic#199286) ## Summary Closes elastic#183245 Closes elastic#197630 [Observability AI Assistant] Partially migrate to inference client replacing `inferenceClient.chatComplete` to `observabilityAIAssistantClient.chat` - `observabilityAIAssistantClient.complete` does a bunch of stuff on top of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper for now because it also adds instrumentation and logging.
… (elastic#199286) ## Summary Closes elastic#183245 Closes elastic#197630 [Observability AI Assistant] Partially migrate to inference client replacing `inferenceClient.chatComplete` to `observabilityAIAssistantClient.chat` - `observabilityAIAssistantClient.complete` does a bunch of stuff on top of `chat`. keepping `observabilityAIAssistantClient.chat` as a wrapper for now because it also adds instrumentation and logging.
Summary
Closes #183245
Closes #197630
[Observability AI Assistant] Partially migrate to inference client
replacing
inferenceClient.chatComplete
toobservabilityAIAssistantClient.chat
-observabilityAIAssistantClient.complete
does a bunch of stuff on top ofchat
. keeppingobservabilityAIAssistantClient.chat
as a wrapper for now because it also adds instrumentation and logging.